<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item v-for="(v, index) in breadcrumbs" :key="index">{{v.title }}</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
</template>

<script>
export default {
name: "Breadcrumb",
  data() {
    return {
      breadcrumbs:[]
    };
  },
  watch:{
    $route() {
      this.getBreadcrumbs()
    }
  },

  created() {
    this.getBreadcrumbs()
  },

  methods: {
    getBreadcrumbs(){
      let list = [
        {
          path: "/index",
          title: "欢迎进入",
        },
      ];
      this.$router.history.current.matched.forEach(function (matched) {
        if (matched.meta.title != list[0].title){
          list.push({
            path: matched.path,
            title: matched.meta.title,
          })
        }
      });
      this.breadcrumbs = list
    }
  },
}
</script>

<style scoped>

</style>